﻿using IntelligentDataCollection.BUS;
using IntelligentDataCollection.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentDataCollection.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LogController : ControllerBase
    {
        public LogController()
        {
        }

        /// <summary>
        ///查询测试数据
        /// </summary>
        /// <returns>success</returns>
        [HttpPost]
        [Route("QueryLog")]
        public ResponseMessage QueryLog(QuerLogInfo querLogInfo)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                LogBUS logBUS = new LogBUS();
                message = logBUS.QueryLog(querLogInfo.StartTime, querLogInfo.EndTime, querLogInfo.DeviceName);
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "失败";
            }

            return message;
        }

        /// <summary>
        ///查询测试数据
        /// </summary>
        /// <returns>success</returns>
        [HttpPost]
        [Route("DeleteLog")]
        public ResponseMessage DeleteLog(List<LogInfo> logs)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                LogBUS logBUS = new LogBUS();
                message = logBUS.DeleteLog(logs);
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "失败";
            }

            return message;
        }

        /// <summary>
        ///查询测试数据
        /// </summary>
        /// <returns>success</returns>
        [HttpPost]
        [Route("ExportLog")]
        public ResponseMessage ExportLog(List<LogInfo> logs)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                LogBUS logBUS = new LogBUS();
                message= logBUS.ExportLog(logs);
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "失败";
            }

            return message;
        }
    }
}
